package com.honweek;

public class TicketTest {
    public static void main(String[] args) {
        Ticket1 tk1 = new Ticket1("窗口一");
        Ticket1 tk2 = new Ticket1("窗口二");
        Ticket1 tk3 = new Ticket1("窗口三");
        tk1.start();
        tk2.start();
        tk3.start();
    }
    }

class Ticket1 extends Thread{
    private static int ticket = 100;
    public Ticket1(){
        super();
    }
        public Ticket1(String name){
            super(name);
        }
    @Override
    public void run() {
        while(true){
            synchronized(Ticket.class){
                if(ticket>0){
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(getName()+"正在售票卖还剩："+ticket--+"张票");
                }
            }
        }
    }
}